package pack03_ovid_partitioner;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author lilulu
 * @date 2023/2/11 1:04
 */
public class CovidBeanMapper extends Mapper<LongWritable, Text,CovidBean, NullWritable> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        String[] split = value.toString().split(",");
        if (split.length < 6) {
            return;
        }

        CovidBean covidBean = new CovidBean();
        covidBean.setDate(split[0]);
        covidBean.setCounty(split[1]);
        covidBean.setState(split[2]);
        covidBean.setFips(split[3]);
        covidBean.setCases(Integer.parseInt(split[4]));
        covidBean.setDeaths(Integer.parseInt(split[5]));

        context.write(covidBean,NullWritable.get());
    }
}
